package com.albaba.designpattern.observer.text_003;

import com.albaba.designpattern.observer.text_002.LotteryResult;

/**
 * @Description: 开奖服务接口
 * @Author zx
 * @Date 2025/2/24 15:41
 * @Version 1.0
 */
public abstract class LotteryService {

    private EventManager eventManager;

    public LotteryService() {

        // 设置事件类型
        eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.Message);
        // 订阅
        eventManager.subscribe(EventManager.EventType.Message, new MessageEventListener());
        eventManager.subscribe(EventManager.EventType.MQ, new MQEventListener());
    }

    public abstract LotteryResult lottery(String uId);

    public LotteryResult lotteryAndMsg(String uId) {
        LotteryResult lotteryResult = lottery(uId);
        // 发送通知
        eventManager.notify(EventManager.EventType.Message, lotteryResult);
        eventManager.notify(EventManager.EventType.MQ, lotteryResult);
        return lotteryResult;
    }

}
